package com.hzcx.app.simplechat.ui.mine.presenter;

import android.app.Activity;
import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.bean.UpLoadImgBean;
import com.hzcx.app.simplechat.model.HomeModel;
import com.hzcx.app.simplechat.model.MomentModel;
import com.hzcx.app.simplechat.model.PublicModel;
import com.hzcx.app.simplechat.model.UserModel;
import com.hzcx.app.simplechat.ui.mine.contract.MineContract;
import com.hzcx.app.simplechat.ui.mine.contract.MineUserInfoContract;
import com.hzcx.app.simplechat.ui.moment.bean.MomentBean;
import com.hzcx.app.simplechat.ui.user.bean.UserInfoBean;
import com.hzcx.app.simplechat.util.UserInfoUtil;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.util.List;

public class MineUserInfoPresenter extends BasePresenter<MineUserInfoContract.View> implements MineUserInfoContract.Presenter {

    /**
     *  获取我的动态列表
     * @param context
     * @param page
     * @param id
     */
    @Override
    public void getMomentList(Context context, int page, int id) {
        MomentModel.getMomentList(context, page, id+"", new BaseObserver<List<MomentBean>>() {
            @Override
            protected void onSuccess(List<MomentBean> data) {
                mView.momentResult(data);
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {
                super.onFailure(e, errorMsg);
                mView.onFail();
            }
        });
    }

    /**
     *  点赞
     * @param context
     * @param id
     */
    @Override
    public void momentFabulous(Context context, int id,int pos) {
        MomentModel.momentFabulous(context, id, new BaseObserver<BaseEmptyBean>() {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.fabulousSuccess(pos);
            }
        });
    }

    /**
     *  删除动态
     * @param context
     * @param id
     * @param pos
     */
    @Override
    public void deleteMoment(Context context, int id, int pos) {
        MomentModel.deleteMoment(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.deleteSuccess(pos);
            }
        });
    }

    /**
     * 收藏图片
     *
     * @param context
     * @param collectdetail
     * @param collectimage
     * @param member_id
     */
    @Override
    public void addChatCollect(Context context, String collectdetail, String collectimage, int member_id) {
        HomeModel.addChatCollect(context, collectdetail, collectimage, member_id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.collectSuccess();
            }
        });
    }

    /**
     *  上传图片
     * @param activity
     * @param url
     */
    @Override
    public void upLoadImg(Activity activity, String url) {
        PublicModel.upLoadImg(activity, TokenUtils.getTokenHeader(), url, new BaseDialogObserver<UpLoadImgBean>(activity) {
            @Override
            protected void onSuccess(UpLoadImgBean data) {
                mView.upLoadImgSuccess(data);
            }
        });
    }

    /**
     *  根据二维码获取用户信息
     * @param context
     * @param url
     */
    @Override
    public void getUserInfoByQrCode(Context context, String url) {
        UserModel.getUserInfoByQrCode(context, url, new BaseDialogObserver<UserInfoBean>(context) {
            @Override
            protected void onSuccess(UserInfoBean data) {
                mView.userInfoResult(data);
            }
        });
    }
}
